package com.online.olsrootserver.controller;

import com.online.olsrootserver.handler.WxMediaHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by littleheng on 2018/5/3
 */
@RestController
@RequestMapping("/image")
public class ApiImageController {

    @Autowired
    private WxMediaHandler apiImageService;

    /**
     * 上传图片
     * @param request
     * @return
     */
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public Map upload(HttpServletRequest request) {
        Map maps = apiImageService.uploadImage("", request);
        return maps;
    }

    /**
     * 上传图片
     * @return
     */
    @RequestMapping(value = "/uploadFromWeChat", method = RequestMethod.POST)
    public Map uploadFromWeChat(@RequestBody Map map) {
        String mediaId = map.get("mediaId").toString();
        Map maps = apiImageService.uploadImage(mediaId, null);
        return maps;
    }

}